//
//  expressDataTableViewCell.m
//  A Learning Walk
//
//  Created by dllo on 16/6/16.
//  Copyright © 2016年 战斗民族. All rights reserved.
//

#import "expressDataTableViewCell.h"



@interface expressDataTableViewCell ()

@property(nonatomic, assign)float heightC;
@property(nonatomic, retain)NSMutableArray *myArr;


@end

@implementation expressDataTableViewCell

-(void)dealloc{
    
    [_labelT release];
    [_labelZ release];
    [_labelS release];
    [_imageT release];
    [_imageN release];
    [_buttonF release];
    
    [_model release];
    
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatCell];
    }
    return self;
}
-(void)creatCell{
    
    self.imageT = [[UIImageView alloc] init];
    self.imageT.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.imageT];
    
//作者
    self.labelZ = [FengLabel LabelwithFrame:CGRectMake(0, 0, 0, 0) Color:[UIColor clearColor] font:15];
    [self.contentView addSubview:self.labelZ];
    
//时间
    self.labelS = [FengLabel LabelwithFrame:CGRectMake(0, 0, 0, 0) Color:[UIColor clearColor] font:15];
    [self.contentView addSubview:self.labelS];
    
//评论按钮
#pragma make 评论点击
    self.buttonF = [FengButton buttonWithType:UIButtonTypeCustom frame:CGRectMake(0, 0, 0, 0) title:@"" image:[UIImage imageNamed:@"123"] color:[UIColor clearColor] handler:^(UIButton *sender) {
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"tiaoZhuan" object:_model];
        
        NSLog(@"评论");
        
    }];
    [self.contentView addSubview:self.buttonF];
    
//内容
    self.labelT = [FengLabel LabelwithFrame:CGRectMake(0, 0, 0, 0) Color:[UIColor clearColor] font:17];
    [self.contentView addSubview:self.labelT];
    self.labelT.numberOfLines = 0;
    
    self.imageN = [[UIImageView alloc] init];
    self.imageN.backgroundColor = [UIColor blackColor];
    [self.contentView addSubview:self.imageN];
    
    [self.imageN release];
    [self.imageT release];
    [self.labelS release];
    [self.labelT release];
    [self.labelZ release];
    
}
-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.imageT.frame = CGRectMake(10, 15, self.contentView.frame.size.width/7, self.contentView.frame.size.width/7);
    
    self.labelZ.frame = CGRectMake(self.imageT.frame.size.width+self.imageT.frame.origin.x+10, 15, self.contentView.frame.size.width/3, 25);

    
    self.labelS.frame = CGRectMake(self.imageT.frame.size.width+self.imageT.frame.origin.x+10, self.labelZ.frame.size.height+self.labelZ.frame.origin.y, self.contentView.frame.size.width/3, self.labelZ.frame.size.height);
    
    self.buttonF.frame = CGRectMake(self.contentView.frame.size.width-40, 15, 30, 30);
    
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17], NSFontAttributeName,nil];
    CGRect rect = [self.model.content boundingRectWithSize:CGSizeMake(self.contentView.frame.size.width-20, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    self.labelT.frame = CGRectMake(10, self.labelS.frame.size.height+self.labelS.frame.origin.y+10, self.contentView.frame.size.width-20, rect.size.height);
    
    if (_model.commentlist != nil) {
        
        self.imageN.frame = CGRectMake(10, self.labelS.frame.size.height+self.labelS.frame.origin.y+10+10+self.labelT.frame.size.height, self.contentView.frame.size.width-20, 250);
    }
}

-(void)setModel:(expressBiao *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [self.imageT sd_setImageWithURL:[NSURL URLWithString:_model.headimg]];
    self.labelZ.text = _model.authorname;
    self.labelS.text = _model.publishtime;
    self.labelT.text = _model.content;
    if (_model.commentlist != nil) {
        
        attachments *attch = [[attachments alloc] init];
        attch = _model.attachments.firstObject;
        [self.imageN sd_setImageWithURL:[NSURL URLWithString:attch.picurl]];
    }
 
}

@end
